home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5391 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: Inter.NL.net!usenet
  2. From: Auke.Reitsma@net.HCC.nl (Auke Reitsma)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Who's dumb: me or my compiler ?
  5. Date: Mon, 12 Feb 1996 22:13:03 GMT
  6. Organization: Inter.NL.net, The Internet Provider in The Netherlands.
  7. Message-ID: <4foe8j$qvn@altrade.nijmegen.inter.nl.net>
  8. References: <4fnmhd$c1o@micky.ibh-dd.de>
  9. Reply-To: Auke.Reitsma@net.HCC.nl
  10. NNTP-Posting-Host: rt99-13.rotterdam.nl.net
  11. X-Newsreader: Forte Free Agent 1.0.82
  12.  
  13. beck@duck.ibh-dd.de (Andre Beck) wrote:
  14.  
  15. > Hi,
  16.  
  17. > I could have had a really bad day searching for this bug, but for
  18. > some lucky circumstances, I trapped it instantly. However I don't
  19. > know whether I wrote bad code or whether a number of compilers do
  20. > it wrong in the same way - the latter doesn't sound that probable ;)
  21.  
  22. > My problem turns around the expression
  23.  
  24. >  x = (*ptr++ << 8) | *ptr++;
  25.  
  26. Ouch.  Order of evaluation, side effects.  Undefined behaviour.
  27.  
  28. > which is pretty simple (IMHO). Read two subsequent bytes from memory
  29. > and make a word off them. Not nice, I know, even endian-dependant. But
  30. > nothing to fail on. Now, GCC fails on 3 different platforms, and DEC
  31. > cc for Ultrix fails as well. Here's my trigger program:
  32.  
  33. Possible solution:
  34.  
  35.   x = (*ptr++ << 8); 
  36.   x |= *ptr++;
  37.  
  38.  
  39. Greetings from Delft, The Netherlands.
  40.  
  41. Auke Reitsma
  42.  
  43.